package com.hspedu.web.homework;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

public class FileUpLoad {
    @RequestMapping("/upload")
    public String upload(@RequestParam("file")MultipartFile file,
                       HttpServletRequest request,
                       String introduce) throws IOException {
        String filename = file.getOriginalFilename();
        System.out.println("文件名"+filename);
        System.out.println("介绍"+introduce);
        String realPath = request.getServletContext().getRealPath("/img/" + filename);
        File file1 = new File(realPath);
        file.transferTo(file1);
        return "success";


    }
}
